package com.i.template.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.i.template.domain.FollowDO;
import com.i.template.domain.UserDO;
import com.i.template.domain.vo.UserVO;
import com.i.template.mapper.FollowerMapper;
import com.i.template.service.IFollowerService;
import com.i.template.service.IUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lewis
 * @type class
 * @description
 * @since 2024/8/8
 */
@Service
@RequiredArgsConstructor
public class FollowerServiceImpl extends ServiceImpl<FollowerMapper, FollowDO> implements IFollowerService {
    private final IUserService userService;
    @Override
//    @Transactional
    public List<UserVO> queryFollowById(Long id) {
        List<FollowDO> list = lambdaQuery().eq(FollowDO::getUserId, id).list();
        List<Long> followingList = list.stream().map(FollowDO::getFollowingId).toList();
        List<UserDO> userDOS = userService.lambdaQuery().in(UserDO::getUid, followingList).list();
        return BeanUtil.copyToList(userDOS,UserVO.class);
    }
}
